package com.yong.automoguding.util;

import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @author Hes
 */
public class CpDailyUtils {
    private CpDailyUtils(){
        throw new NoSuchMethodError();
    }

    /**
     * 填写单选 / 多选表单
     * 第一个是正确答案
     * @param forms 表单
     */
    public static void fillItemForms(List<Map> forms) {

        forms.stream().filter(map -> {
          Integer fieldType = (Integer) map.get("fieldType");
          String title = (String) map.get("title");
          return (fieldType.equals(2) || fieldType.equals(3)) && !title.contains("你今天所处的位置是");
        }).forEach(map -> {
            List<Map> fieldItems = (List<Map>) map.get("fieldItems");
            Map selected = fieldItems.get(0);
            selected.put("isSelected", 1);
            map.put("fieldItems", Collections.singletonList(selected));
        });

        forms.stream().filter(map -> {
            Integer fieldType = (Integer) map.get("fieldType");
            return fieldType.equals(1);
        }).forEach(map -> {
            map.put("value", "37");
        });

        // 位置单独填写
        forms.stream().filter(map -> {
            String title = (String) map.get("title");
            return title.contains("你今天所处的位置是");
        }).forEach(map -> {
            List<Map> fieldItems = (List<Map>) map.get("fieldItems");
            Map selected = fieldItems.get(5);
            selected.put("isSelected", 1);
            map.put("fieldItems", Collections.singletonList(selected));
        });

    }
}
